package com.xiyoumobile.dengtuo.flowershop;

import android.app.Activity;
import android.content.Intent;
import android.hardware.input.InputManager;
import android.os.Bundle;
import android.view.View;
import android.view.inputmethod.InputMethodManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.TextView;
import android.widget.Toast;

public class LoginActivity extends Activity {
    ImageButton imageButton;
    EditText password;
    EditText account;
    Button login;
    InputMethodManager imm;

    private TextView register;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_login);
        findView();
    }

    private void findView() {

        imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE);
        imageButton = (ImageButton) findViewById(R.id.title_bar_back);
        imageButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                finish();
            }
        });


        password = (EditText)findViewById(R.id.password);
        account = (EditText)findViewById(R.id.userAcount);
        login = (Button)findViewById(R.id.login);
        login.setOnClickListener(new ButtonOnClickLisenter());

        register = (TextView)findViewById(R.id.register);
        register.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                Intent intent = new Intent(LoginActivity.this,RegisterActivity.class);
                startActivity(intent);
            }
        });
    }

    private class ButtonOnClickLisenter implements View.OnClickListener {

        @Override
        public void onClick(View v) {
            if (imm != null) {
                imm.hideSoftInputFromWindow(getWindow().getDecorView().getWindowToken(), 0);
            }

            //判断网络

            //判断条件
            if (null == account.getText().toString() || account.getText().toString().isEmpty()) {
                Toast.makeText(LoginActivity.this, "请输入账号", Toast.LENGTH_SHORT).show();
                return;
            }
            //判断条件
            if (null == password.getText().toString() || password.getText().toString().isEmpty()) {
                Toast.makeText(LoginActivity.this, "请输入密码", Toast.LENGTH_SHORT).show();
                return;
            }

            //开始请求
        }
    }
}
